package com.fengling.controller;

import com.fengling.pojo.Emp;
import com.fengling.pojo.Result;
import com.fengling.service.EmpService;
import com.fengling.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j

public class LoginController {
    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("登录信息:{}",emp);
        Emp getBack=empService.login(emp);
        if(getBack!=null){
            Map<String,Object> claims=new HashMap<>();
            claims.put("id",getBack.getId());
            claims.put("username",getBack.getUsername());
            claims.put("name",getBack.getName());

            String jwt=JwtUtils.generateJwt(claims);
            return Result.success(jwt);


        }
        return Result.error("不对byd");




    }






}
